import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEMap } from './ipsdemap';
import { IPSDEMapField } from './ipsdemap-field';
import { IPSDEField } from '../defield/ipsdefield';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDEMapDetailImpl extends PSModelObjectImpl implements IPSDEMapField {
  get codeName(): string {
    return this.M.codeName;
  }

  get dstFieldName(): string {
    return this.M.dstFieldName;
  }

  protected dstpsdefield: IPSDEField | null = null;

  getDstPSDEField(): IPSDEField | null {
    if (this.dstpsdefield != null) return this.dstpsdefield;
    const value = this.M.getDstPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdemap = this.getParentPSModelObject('dataentity.datamap.IPSDEMap') as IPSDEMap;
    if (ipsdemap != null) {
      this.dstpsdefield = ipsdemap.getDstPSDEMust().findPSDEField(value);
    }
    return this.dstpsdefield;
  }

  get dstPSDEField(): IPSDEField | null {
    return this.getDstPSDEField();
  }

  getDstPSDEFieldMust(): IPSDEField {
    const value = this.getDstPSDEField();
    if (value == null) {
      throw new Error('未指定目标实体属性');
    }
    return value;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get expression(): string {
    return this.M.expression;
  }

  get mapType(): 'FIELD' | 'VALUE' | 'EXPRESSION' | 'VALUE_SRC' | 'EXPRESSION_SRC' {
    return this.M.mapType;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  get rawValue(): string {
    return this.M.rawValue;
  }

  get srcFieldName(): string {
    return this.M.srcFieldName;
  }

  protected srcpsdefield: IPSDEField | null = null;

  getSrcPSDEField(): IPSDEField | null {
    if (this.srcpsdefield != null) return this.srcpsdefield;
    const value = this.M.getSrcPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.srcpsdefield = ipsdataentity.findPSDEField(value);
    }
    return this.srcpsdefield;
  }

  get srcPSDEField(): IPSDEField | null {
    return this.getSrcPSDEField();
  }

  getSrcPSDEFieldMust(): IPSDEField {
    const value = this.getSrcPSDEField();
    if (value == null) {
      throw new Error('未指定源实体属性');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSDEMapDetailImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.datamap.IPSDEMapField') return true;
    return super.instanceof(cls);
  }
}
